#启动谷歌浏览器
from selenium.webdriver import Chrome
from selenium.webdriver.common.keys import Keys

#创建浏览器对象
web = Chrome()
#打开一个网站
web.get('http://lagou.com')
print(web.title)

#点击
el = web.find_element_by_xpath('//*[@id="changeCityBox"]/ul/li[1]/a')
el.click()

#输入信息，点击回车
web.find_element_by_xpath('//*[@id="search_input"]').send_keys("python", Keys.ENTER)

l = web.find_elements_by_xpath('//*[@id="jobList"]/div[1]/div')
print(l)
i = 1
for li in l:
    job_name = li.find_element_by_xpath('./div[1]/div[1]/div[1]/a').text
    li.find_element_by_xpath('./div[1]/div[1]/div[1]/a').click()
    job_price = li.find_element_by_xpath('./div[1]/div[1]/div[2]/span').text
    # comp = li.find_element_by_xpath('./div[1]/div[2]/div[1]/a').text
    comp = li.find_element_by_xpath('./div[1]/div[2]/div[1]/a').text
    print(job_name)
    print(job_price)
    print(comp)
    if i == 1:
        break

web.switch_to.window(web.window_handles[-1])

print(web.find_element_by_xpath('//*[@id="job_detail"]/dd[2]/div').text)

# #iframe 处理
# iframe = web.find_element_by_xpath('')
# web.switch_to.frame(iframe)
# '''
# '''
# web.switch_to.default_content() #切回原页面
